<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
 * 招聘模块
 */
class Company extends Api
{
    protected $noNeedLogin = ['getRegionList','getIndustryList','getPositionList','getPayMoneyList','getWorkTypeList','getCompanyPageList','getCompanyDetail','getCompanyPositionDetail'];
    protected $noNeedRight = ['*'];



    /**
     * 获取地区列表
     */
    public function getRegionList(\app\common\model\RegionModel $RegionModel)
    {
        $return = $RegionModel->getList();
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取行业列表
     */
    public function getIndustryList(\app\common\model\IndustryModel $IndustryModel)
    {
        $return = $IndustryModel->getList();
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取岗位列表
     */
    public function getPositionList(\app\common\model\PositionModel $PositionModel)
    {
        $return = $PositionModel->getList();
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取薪资筛选列表
     */
    public function getPayMoneyList(\app\common\model\PayMoneyModel $PayMoneyModel)
    {
        $return = $PayMoneyModel->getList();
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取工种筛选列表
     */
    public function getWorkTypeList(\app\common\model\WorkTypeModel $WorkTypeModel)
    {
        $return = $WorkTypeModel->getList();
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取公司列表
     *
     * @ApiTitle    (获取公司列表)
     * @ApiSummary  (获取公司列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/company/getCompanyPageList)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams   (name="search", type="string", required=false, description="搜索")
     * @ApiParams   (name="money", type="string", required=false, description="金额")
     * @ApiParams   (name="region", type="string", required=false, description="地区")
     * @ApiParams   (name="work_type_id", type="integer", required=false, description="工种ID")
     *
     * @ApiParams   (name="region_id", type="integer", required=false, description="地区ID")
     * @ApiParams   (name="industry_id", type="integer", required=false, description="行业ID")
     * @ApiParams   (name="position_id", type="integer", required=false, description="岗位ID")
     * @ApiParams   (name="pay_money_id", type="integer", required=false, description="薪资筛选ID")
     * @ApiParams   (name="page", type="integer", required=true, description="页码")
     * @ApiParams   (name="limit", type="integer", required=true, description="条数")
     */
    public function getCompanyPageList(\app\common\model\CompanyModel $CompanyModel)
    {
        $search = $this->request->request('search');
        $region = $this->request->request('region');
        $money = $this->request->request('money');
        $region_id = $this->request->request('region_id');
        $industry_id = $this->request->request('industry_id');
        $position_id = $this->request->request('position_id');
        $pay_money_id = $this->request->request('pay_money_id');
        $work_type_id = $this->request->request('work_type_id');
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',5);
        $user_id = $this->auth->id;
        $return = $CompanyModel->getPageList($search, $region, $money, $region_id, $industry_id, $position_id, $pay_money_id, $work_type_id, $page, $limit);
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取公司详情
     *
     * @ApiTitle    (获取公司详情)
     * @ApiSummary  (获取公司详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/company/getCompanyDetail/company_id/{company_id})
     * @ApiParams   (name="company_id", type="integer", required=true, description="公司ID")
     */
    public function getCompanyDetail(\app\common\model\CompanyModel $CompanyModel)
    {
        $company_id = $this->request->request('company_id');
        $user_id = $this->auth->id;
        $return = $CompanyModel->getDetail($company_id);
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 获取公司职位详情
     *
     * @ApiTitle    (获取公司职位详情)
     * @ApiSummary  (获取公司职位详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/company/getCompanyPositionDetail/company_company_id/{company_company_id})
     * @ApiParams   (name="company_company_id", type="integer", required=true, description="公司职位ID")
     */
    public function getCompanyPositionDetail(\app\common\model\CompanyPositionModel $CompanyPositionModel)
    {
        $company_company_id = $this->request->request('company_company_id');
        $user_id = $this->auth->id;
        $return = $CompanyPositionModel->getDetail($company_company_id);
        $this->success($return['msg'],$return['data'],$return['code']);
    }

    /**
     * 报名登记
     *
     * @ApiTitle    (报名登记)
     * @ApiSummary  (报名登记)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/company/apply)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_id", type="integer", required=false, description="企业Id")
     * @ApiParams   (name="company_position_id", type="integer", required=false, description="职位Id")
     * @ApiParams   (name="name", type="integer", required=false, description="姓名")
     * @ApiParams   (name="mobile", type="integer", required=false, description="联系方式")
     * @ApiParams   (name="file", type="integer", required=true, description="图片")
     * @ApiParams   (name="sex", type="string", required=true, description="性别")
     * @ApiParams   (name="date", type="string", required=true, description="出生年份")
     * @ApiParams   (name="education", type="string", required=true, description="学历")
     */
    public function apply(\app\common\model\ApplyModel $ApplyModel)
    {
        $user_id = $this->auth->id;
        $company_id = $this->request->request('company_id');
        $company_position_id = $this->request->request('company_position_id');
        $name = $this->request->request('name');
        $mobile = $this->request->request('mobile');
        $file = $this->request->request('file');
        $sex = $this->request->request('sex');
        $date = $this->request->request('date');
        $education = $this->request->request('education');
        if (!$company_id || !$company_position_id || !$name || !$mobile || !$sex || !$date || !$education) {
            $this->error('请填写完整表单信息');
        }
        $return = $ApplyModel->apply($user_id, $company_id, $company_position_id, $name, $mobile, $file, $sex, $date, $education);
        $this->success($return['msg'],$return['data'],$return['code']);
    }


}